home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_052 / tek4010 / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  279 lines

  1. /*
  2. .index main.c
  3.  */
  4. /************************************************************************
  5.  *  vt100 terminal emulator with xmodem transfer capability
  6.  *  written by Michael Mounier
  7.  *  new version by Dave Wecker
  8.  * Tek 4010 emulation added, and several bug fixes T.Whelan
  9.  * this version has trouble at 19200 bps in tek mode but not in vt100
  10.  * sugestions would be appreciated. I have managed for plain text ( no scroll)
  11.  * data rates of about 15000 bps, but scrolling makes this much worse. This
  12.  * version lets AmigaDOS do the X-On/X-Off as it wants to. Amiga Dos 1.2
  13.  * will let the user control this.
  14.  
  15.  * T.Whelan
  16.  * Dept of Physics & Astronomy
  17.  * University of Iowa
  18.  * Iowa City
  19.  * IA 52244
  20.  * 
  21.  * SPAN: IOWA::WHELAN
  22.  * bitnet - too unreliable.
  23.  *
  24.  *           860823 DBW - Integrated and rewrote lots of code
  25.  *      v2.0 860809 DBW - Major rewrite
  26.  *      v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
  27.  *      v1.0 860712 DBW - First version released
  28.  *
  29.  *
  30.  ************************************************************************/
  31.  
  32. /*  all includes defines and globals */
  33. #define MODULE_MAIN
  34. #include "vt100.h"
  35. /******************************************************/
  36. /*                   Main Program                     */
  37. /*                                                    */
  38. /*      This is the main body of the program.         */
  39. /******************************************************/
  40. FILE * tranr = NULL;
  41. FILE * trans = NULL;
  42. int send;
  43.  
  44. /*
  45. .page.index main
  46.  */
  47. main(argc,argv)
  48. int     argc;
  49. char    **argv;
  50.     {
  51.     ULONG class;
  52.     unsigned int code;
  53.     int la, dola, actual;
  54.     char c, *base, *this, *exitloop;
  55.  
  56.     base = NULL;             /* avoid a Lattice warning message */
  57.     InitDefaults (argc,argv);
  58.     InitDevs ();
  59.     InitTek (mywindow->UserPort);
  60.     InitMenu ();
  61.     
  62.     KeepGoing =     TRUE;
  63.     send      =     FALSE;
  64.     maxcol    =     MAXX / 8;
  65.     x         =     MINX ; 
  66.     y         =     MINY; 
  67.     curmode   =     0;
  68.     script_on =     FALSE;
  69.     script_wait=    TRUE;
  70.     SetAPen (mywindow->RPort,1);
  71.     cursoron ();
  72.     cursoroff ();    
  73.     emit (12);
  74.     BeginIO (Read_Request);
  75.     while( KeepGoing )
  76.             {
  77.             /* wait for window message or serial port message */
  78.             cursoron ();
  79.             if (script_wait)    /* if script ready dont wait here */
  80.                 Wait(
  81.                  (1L << Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit) |
  82.                  (1L << mywindow->UserPort->mp_SigBit) |
  83.                  (1L << Script_Timer_Port->mp_SigBit));
  84.             cursoroff ();
  85. #if 0
  86.             /* do ascii file send */
  87.             if (send)
  88.                 {
  89.                 if ((c = getc (trans)) != EOF) {
  90.                     if (c == '\n') c = '\r';
  91.                     sendchar (c);
  92.                     }
  93.                 else {
  94.                     fclose (trans);
  95.                     emits ("\nFile Sent\n");
  96.                     send = FALSE;
  97.                     }
  98.                 }
  99. #endif
  100.             /* see if there are any characters from the host */
  101.             if (CheckIO (Read_Request)) 
  102.         {
  103.                 WaitIO (Read_Request);
  104.                 doremote (rs_in[0]);
  105. #if 0
  106.                 if (script_on) chk_script (rs_in[0]);
  107. #endif
  108.                 Read_Request->IOSer.io_Command = SDCMD_QUERY;
  109.                 BeginIO (Read_Request);
  110.                 WaitIO (Read_Request);
  111.                 Read_Request->IOSer.io_Command = CMD_READ;
  112.                 actual = (int) Read_Request->IOSer.io_Actual;
  113.                 if (actual > 0) 
  114.             {
  115.                     Read_Request->IOSer.io_Length =
  116.                                                Read_Request->IOSer.io_Actual;
  117.                     BeginIO (Read_Request);
  118.                 WaitIO (Read_Request);
  119.                     Read_Request->IOSer.io_Length = 1;
  120.  
  121.             dola = 0;
  122.             la = 0;
  123.             this = &rs_in[0];
  124.             exitloop = this + actual;
  125.                     for (; this < exitloop; this++) 
  126.             {
  127. #if 0
  128.                         if (script_on) chk_script (&this);
  129. #endif
  130.                         if (dola != 0) 
  131.                 {
  132.                             if (isprint (*this)) 
  133.                 la++;
  134.                             else 
  135.                 {
  136.                 /* ok, got a non printing char, let's dump
  137.                  * whatever has come heretofore.
  138.                  */
  139.                                 if (la > 0)
  140.                                     emitbatch (la,base);
  141.                                 doremote (*this);
  142.                 /* reset state variables */
  143.                 la = 0;
  144.                                 dola = 0;
  145.                                 } /* end handling of non-printing chars */
  146.                             }
  147.                         else /* dola is == 0 */
  148.                 {
  149.                             doremote (*this);
  150.                 /* doremote () has set these control flags: */
  151.                             if (inesc < 0 && inctrl  <  0 && a[alt]  == 0) 
  152.                 {
  153.                                 dola = 1;
  154.                     base = this + 1;
  155.                     la = 0;
  156.                     }
  157.                             } /* endifthenelse (dola!=0) */
  158.                         } /* end for loop(; this < exitloop; this++) */
  159.  
  160.                     /* dump anything left in the lookahead buffer */
  161.                     if (la > 0) 
  162.                         emitbatch (la, base);
  163.  
  164.                     } /* endif (actual > 0) */
  165.                 BeginIO (Read_Request);
  166.  
  167.                 } /* endif (CheckIO (Read_Request)) */
  168. /*
  169. .page
  170.  */
  171.         /* ok, you handled whatever i/o came from the serial port, now
  172.          * handle whatever the operator has for you from the menu or
  173.          * from the keyboard.
  174.          */
  175.             while (NewMessage = (struct IntuiMessage *)
  176.         GetMsg (mywindow->UserPort) )
  177.                 {
  178.                 class = NewMessage->Class;
  179.                 code = NewMessage->Code;
  180.                 ReplyMsg (NewMessage);
  181.                 switch( class )
  182.                     {
  183.                     case RAWKEY:
  184.             c = toasc(code,0);
  185.                     break;
  186.                     case MENUPICK:
  187.                         if ( code != MENUNULL ) 
  188.                 menupick(code);
  189.                     }/* end switch */
  190.  
  191.                 }/* endwhile ( newmessage ) */
  192.  
  193.             if (!script_wait || 
  194.                 (CheckIO(&Script_Timer) && script_wait == WAIT_TIMER)) 
  195.                 do_script_cmd(NEXTCOMMAND);
  196.  
  197.             }  /* end while ( keepgoing ) */
  198.                 
  199.     /*   It must be time to quit, so we have to clean
  200.      *   up and exit.
  201.      */
  202.     CloseDevice (&Timer);
  203.     DeletePort (Timer_Port);
  204.     CloseDevice (&Script_Timer);
  205.     DeletePort (Script_Timer_Port);
  206.     CloseDevice (Read_Request);
  207.     DeletePort (Read_Request->IOSer.io_Message.mn_ReplyPort);
  208.     FreeMem (Read_Request,(long)sizeof(*Read_Request));
  209.     CloseDevice (Write_Request);
  210.     DeletePort (Write_Request->IOSer.io_Message.mn_ReplyPort);
  211.     FreeMem (Write_Request,(long)sizeof(*Write_Request));
  212.     ClearMenuStrip (mywindow);
  213.     CloseWindow (mywindow);
  214.     CloseTek ();
  215.     exit (FALSE);
  216.     } /* end main */
  217. /*
  218. .page.index do_capture
  219.  */
  220. do_capture (file)
  221. char * file;
  222. {
  223.     static int capture;
  224.  
  225.     if (capture == TRUE)
  226.         {
  227.         capture = FALSE;
  228.         fclose (tranr);
  229.         emits ("\nEnd File Capture\n");
  230.         }
  231.     else
  232.         {
  233.         if (file == NULL) 
  234.         {
  235.             emits ("\nAscii Capture:");
  236.             filename (name);
  237.             } 
  238.         else 
  239.         strcpy(name, file);
  240.         if ((tranr = fopen (name,"w")) == 0)
  241.             {
  242.             capture = FALSE;
  243.             emits ("\nError Opening File\n");
  244.             return (FALSE);
  245.             }
  246.         capture = TRUE;
  247.         }
  248. }/* end do_capture */
  249. /*
  250. .index do_send
  251.  */
  252. do_send (file)
  253. char *file;
  254. {
  255.     if (send == TRUE)
  256.         { 
  257.         send = FALSE;
  258.         fclose (trans);
  259.         emits ("\nFile Send Cancelled\n");
  260.         }
  261.     else
  262.         {
  263.         if (file == NULL) 
  264.         {
  265.             emits ("\nAscii Send:");
  266.             filename (name);
  267.             }
  268.         else 
  269.             strcpy(name, file);
  270.         if ((trans = fopen (name,"r")) == 0)
  271.             {
  272.             send = FALSE;
  273.             emits ("\nError Opening File\n");
  274.             return (FALSE);
  275.             }
  276.         send = TRUE;
  277.         }
  278. }/* end do_send */
  279.